package dao;

import java.util.List;
import javax.persistence.Query;
import entity.Users;

public class UsersDao extends BaseDao<Users> {
	
	public static UsersDao INSTANCE = new UsersDao();
	
	private UsersDao() {}

	@SuppressWarnings("unchecked")
	public List<Users> findAll() {
		Query query = em.createNamedQuery("Users.findAll");
		return query.getResultList();
	}
	
	public Users authenticate(String username, String password){
		String sql = "SELECT u FROM Users u WHERE u.username = :username AND u.password = :password";
		Query query = em.createQuery(sql);
		query.setParameter("username", username);
		query.setParameter("password", password);
		return (Users) query.getSingleResult();
	}
}
